<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class DataBank {

    private $db;
    private $_kdkppn;
    private $_vendor_name;
    private $_amount;
    private $_currency_code;
    private $_exchage_rate;
    private $_exchange_date;
    private $_invoice_num;
    private $_invoice_date;
    private $_description;
    private $_check_number;
    private $_check_date;
    private $_base_amount;
    private $_bank_account_name;
    private $_attribute15;
    private $_status_lookup_code;
    private $_creation_date;
    private $_ce_bank_acct_use_id;
    private $_invoice_id;
    private $_jenis_sp2d;
    private $_jenis_spm;
    private $_jendok;
    private $_segment1;
    private $_nmsatker;    
    private $_join1;
    private $_join2;
    private $_error;
    private $_valid = TRUE;
    private $_table = 'AP_CHECKS_ALL_V';
    public $registry;

    /*
     * konstruktor
     */

    public function __construct($registry = Registry) {
        $this->db = $registry->db;
        $this->registry = $registry;
    }

    public function get_sp2d_backdate($filter) {
        $sql = "SELECT  A.KDKPPN,
                TO_CHAR(A.CREATION_DATE,'DD-MM-YYYY HH24:MI:SS') CREATION_DATE,
                A.CHECK_NUMBER, A.CHECK_DATE, 
                A.INVOICE_NUM, A.INVOICE_DATE, 
                A.AMOUNT,
                B.BANK_NAME , B.NAMA_REK,  
                A.DESCRIPTION,
                A.STATUS_LOOKUP_CODE
                FROM AP_CHECKS_ALL_V A
                LEFT JOIN T_BANK_BAYAR B
                ON A.CE_BANK_ACCT_USE_ID = B.BANK_ACCT_USE_ID
                WHERE 1=1
                AND CHECK_DATE BETWEEN TO_DATE ('".Session::get('ta')."0101','YYYYMMDD') AND TO_DATE ('".Session::get('ta')."1231','YYYYMMDD') 
                AND TO_CHAR(CREATION_DATE,'YYYYMMDD')  > TO_CHAR(CHECK_DATE,'YYYYMMDD')
                AND STATUS_LOOKUP_CODE <> 'VOIDED'";
        //SP2D = 140181301002823
        $no = 0;
        //var_dump($filter);
        foreach ($filter as $filter) {
            $sql .= " AND " . $filter;
        }
        $sql .= " ORDER BY CHECK_DATE DESC, CREATION_DATE DESC";
        //var_dump ($sql);
        $result = $this->db->select($sql);
        $data = array();
        foreach ($result as $val) {
            $d_data = new $this($this->registry);
            $d_data->set_kdkppn($val['KDKPPN']);
            $d_data->set_creation_date($val['CREATION_DATE']);
            $d_data->set_check_number($val['CHECK_NUMBER']);
            $d_data->set_check_date(date("d-m-Y", strtotime($val['CHECK_DATE'])));
            $d_data->set_invoice_num($val['INVOICE_NUM']);
            $d_data->set_invoice_date(date("d-m-Y", strtotime($val['INVOICE_DATE'])));
            $d_data->set_amount($val['AMOUNT']);
            $d_data->set_description($val['DESCRIPTION']);
            $d_data->set_join1($val['BANK_NAME']);
            $d_data->set_join2($val['NAMA_REK']);
            $data[] = $d_data;
        }
        return $data;
    }
    
    public function get_sp2d_sudah_void($filter) {
        $sql = "SELECT  A.KDKPPN,
                TO_CHAR(A.CREATION_DATE,'DD-MM-YYYY HH24:MI:SS') CREATION_DATE,
                A.CHECK_NUMBER, A.CHECK_DATE, 
                A.INVOICE_NUM, A.INVOICE_DATE, 
                A.AMOUNT,
                B.BANK_NAME , B.NAMA_REK,  
                A.DESCRIPTION,
                A.STATUS_LOOKUP_CODE
                FROM ".$this->_table." A
                LEFT JOIN T_BANK_BAYAR B
                ON A.CE_BANK_ACCT_USE_ID = B.BANK_ACCT_USE_ID
				WHERE 1=1 
                AND STATUS_LOOKUP_CODE = 'VOIDED'
                AND EXTRACT(YEAR FROM CHECK_DATE) = '2015'
                ";
        //SP2D = 140181301002823
        $no = 0;
        //var_dump($filter);
        foreach ($filter as $filter) {
            $sql .= " AND " . $filter;
        }
        $sql .= " ORDER BY CHECK_DATE DESC, CREATION_DATE DESC";
        //var_dump ($sql);
        $result = $this->db->select($sql);
        $data = array();
        foreach ($result as $val) {
            $d_data = new $this($this->registry);
            $d_data->set_kdkppn($val['KDKPPN']);
            $d_data->set_creation_date($val['CREATION_DATE']);
            $d_data->set_check_number($val['CHECK_NUMBER']);
            $d_data->set_check_date(date("d-m-Y", strtotime($val['CHECK_DATE'])));
            $d_data->set_invoice_num($val['INVOICE_NUM']);
            $d_data->set_invoice_date(date("d-m-Y", strtotime($val['INVOICE_DATE'])));
            $d_data->set_amount($val['AMOUNT']);
            $d_data->set_description($val['DESCRIPTION']);
            $d_data->set_join1($val['BANK_NAME']);
            $d_data->set_join2($val['NAMA_REK']);
            $data[] = $d_data;
        }
        return $data;
    }
    
    /*
     * setter
     */

    public function set_kdkppn ($kdkppn) {
        $this->_kdkppn = $kdkppn;
    }

    public function set_vendor_name($vendor_name) {
        $this->_vendor_name = $vendor_name;
    }

    public function set_amount($amount) {
        $this->_amount = $amount;
    }

    public function set_currency_code($currency_code) {
        $this->_currency_code = $currency_code;
    }

    public function set_exchange_rate($exchange_rate) {
        $this->_exchange_rate = $exchange_rate;
    }

    public function set_invoice_num($invoice_num) {
        $this->_invoice_num = $invoice_num;
    }

    public function set_invoice_date($invoice_date) {
        $this->_invoice_date = $invoice_date;
    }

    public function set_description($description) {
        $this->_description = $description;
    }

    public function set_check_number($check_number) {
        $this->_check_number = $check_number;
    }

    public function set_check_date($check_date) {
        $this->_check_date = $check_date;
    }

    public function set_base_amount($base_amount) {
        $this->_base_amount = $_base_amount;
    }

    public function set_bank_account_name($bank_account_name) {
        $this->_bank_account_name = $bank_account_name;
    }

    public function set_attribute15($attribute15) {
        $this->_attribute15 = $attribute15;
    }

    public function set_status_lookup_code($status_lookup_code) {
        $this->_status_lookup_code = $status_lookup_code;
    }

    public function set_creation_date($creation_date) {
        $this->_creation_date = $creation_date;
    }

    public function set_ce_bank_acct_use_id($ce_bank_acct_use_id) {
        $this->_ce_bank_acct_use_id = $ce_bank_acct_use_id;
    }

    public function set_invoice_id($invoice_id) {
        $this->_invoice_id = $invoice_id;
    }

    public function set_jenis_sp2d($jenis_sp2d) {
        $this->_jenis_sp2d = $jenis_sp2d;
    }

    public function set_jenis_spm($jenis_spm) {
        $this->_jenis_spm = $jenis_spm;
    }

    public function set_jendok($jendok) {
        $this->_jendok = $jendok;
    }

    public function set_segment1($segment1) {
        $this->_segment1 = $segment1;
    }

    public function set_nmsatker($nmsatker) {
        $this->_nmsatker = $nmsatker;
    }

    public function set_join1($join1) {
        $this->_join1 = $join1;
    }

    public function set_join2($join2) {
        $this->_join2 = $join2;
    }

    /*
     * getter
     */

    public function get_kdkppn() {
        return $this->_kdkppn;
    }

    public function get_vendor_name() {
        return $this->_vendor_name;
    }

    public function get_amount() {
        return $this->_amount;
    }

    public function get_currency_code() {
        return $this->_currency_code;
    }

    public function get_exchange_rate() {
        return $this->_exchange_rate;
    }

    public function get_exchange_date() {
        return $this->_exchange_date;
    }

    public function get_invoice_num() {
        return $this->_invoice_num;
    }

    public function get_invoice_date() {
        return $this->_invoice_date;
    }

    public function get_description() {
        return $this->_description;
    }

    public function get_check_number() {
        return $this->_check_number;
    }

    public function get_check_date() {
        return $this->_check_date;
    }

    public function get_base_amount() {
        return $this->_base_amount;
    }

    public function get_bank_account_name() {
        return $this->_bank_account_name;
    }

    public function get_attribute15() {
        return $this->_attribute15;
    }

    public function get_status_lookup_code() {
        return $this->_status_lookup_code;
    }

    public function get_creation_date() {
        return $this->_creation_date;
    }

    public function get_ce_bank_acct_use_id() {
        return $this->_ce_bank_acct_use_id;
    }

    public function get_invoice_id() {
        return $this->_invoice_id;
    }

    public function get_jenis_sp2d() {
        return $this->_jenis_sp2d;
    }

    public function get_jenis_spm() {
        return $this->_jenis_spm;
    }

    public function get_jendok() {
        return $this->_jendok;
    }

    public function get_segment1() {
        return $this->_segment1;
    }

    public function get_nmsatker() {
        return $this->_nmsatker;
    }

    public function get_join1() {
        return $this->_join1;
    }

    public function get_join2() {
        return $this->_join2;
    }

    public function get_table() {
        return $this->_table;
    }
    /*
     * destruktor
     */

    public function __destruct() {
        
    }

}
